package com.zh.Exhandler;

import com.zh.Exception.AddressBookNONE;
import com.zh.Exception.CategoryExistsDishException;
import com.zh.Exception.DuplicateException;
import com.zh.Exception.ShoppingCartNONE;
import com.zh.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(CategoryExistsDishException.class)  //拦截异常 可自定义拦截异常种类
    public Result<String> CategoryExistsDishException(CategoryExistsDishException e) {
        log.info("{}",e.getMessage());
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(DuplicateException.class)
    public Result<String> DuplicateException(DuplicateException e) {
        log.info("{}",e.getMessage());
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(ShoppingCartNONE.class)
    public Result<String> ShoppingCartNONE(ShoppingCartNONE e) {
        log.info("{}",e.getMessage());
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(AddressBookNONE.class)
    public Result<String> AddressBookNONE(AddressBookNONE e) {
        log.info("{}",e.getMessage());
        return Result.error(e.getMessage());
    }
}